import { Observable } from './Observable';
export function map(project: Function) {
  // operation 传入老的observable，返回新的observable
  return (source: any) => {
    const observable = new Observable(function (subscriber) {
      // 先调用啦的observable的subscribe订阅，然后重写observer对象
      return source.subscribe({
        ...subscriber,
        // 最关键就是要重写next，此value为老的observable传递过来的value
        next: (value: any) => {
          // 把老的Observable值传给映射函数作为参数
          // 然后把映射函数返回结果传递给新的observable
          subscriber.next(project(value));
        }
      });
    });
    return observable;
  };
}
